package com.lx.mobileplayer.mvp.view.fragment

import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.lx.mobileplayer.mvp.view.Iview.IBaseView
import com.lx.mobileplayer.utils.LogUtil

/**
 * 类说明：所有fragment的基类
 * Created by liuxiong on 2019/4/22.
 */
abstract class BaseFragment: Fragment() ,IBaseView{

    private val rootView by lazy{
        initContentView()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        LogUtil.setCurrentTag(this.javaClass.simpleName)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

        return rootView
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

        initView()
        initData()
    }

    /**
    * 方法说明:  初始化内容view
    * @return
    * created by liuxiong on 14:37
    */
    abstract fun initContentView(): View

    override fun getMContext(): Activity {
        return this.activity as Activity
    }

    override fun getAppContext(): Context {
        return  getMContext().applicationContext
    }


    /**
     * 方法说明:  初始化控件
     * created by liuxiong on 2019/4/24 14:13
     */
    open fun initView(){}

    /**
     * 方法说明:  初始化数据
     * created by liuxiong on 2019/4/24 14:15
     */
    open fun initData(){}
}